﻿namespace MicroCloud.Message
{
    /// <summary>
    /// 业务契约：消息服务
    /// </summary>
    public interface IMessageService
    {
        #region 属性
        /// <summary>
        /// 获取 消息查询数据集
        /// </summary>
        IQueryable<MessageEntity> Messages { get; }

        /// <summary>
        /// 获取 消息接收者查询数据集
        /// </summary>
        IQueryable<MessageReceiver> MessageReceivers { get; }

        /// <summary>
        /// 获取 模板消息查询数据集
        /// </summary>
        IQueryable<TemplateMessage> TemplateMessages { get; }

        #endregion

        #region 方法
        #region "创建消息"
        /// <summary>
        /// 创建消息
        /// </summary>
        /// <param name="dtos">消息DTO</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> CreateMessages(params MessageInputDto[] dtos);
        #endregion
        #region "更新消息"
        /// <summary>
        /// 更新消息
        /// </summary>
        /// <param name="dtos">消息DTO</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> UpdateMessages(params MessageInputDto[] dtos);
        #endregion
        #region "删除消息"
        /// <summary>
        /// 删除消息
        /// </summary>
        /// <param name="ids">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> DeleteMessages(params long[] ids);
        #endregion

        #region "发送消息"
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="messageIds">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> SendMessages(params long[] messageIds);
        #endregion
        #region "获取消息"
        /// <summary>
        /// 获取消息
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="messageIds">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult<MessageDto[]>> GetMessages(long userId = default, params long[] messageIds);
        #endregion
        #region "获取未阅读消息"
        /// <summary>
        /// 获取未阅读消息
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult<MessageDtoSimple[]>> GetUnreadMessages(long userId = default);
        #endregion
        #region "阅读消息"
        /// <summary>
        /// 阅读消息
        /// </summary>
        /// <param name="readWay">阅读方式</param>
        /// <param name="userId">用户编号</param>
        /// <param name="read">已读/未读</param>
        /// <param name="messageIds">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> ReadMessages(MessageSendWay readWay, long userId, bool read, params long[] messageIds);
        #endregion
        #region "删除消息接收者"
        /// <summary>
        /// 删除消息接收者
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="messageIds">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> DeleteMessageReceiver(long userId, params long[] messageIds);
        #endregion

        #region "创建模板消息"
        /// <summary>
        /// 创建模板消息
        /// </summary>
        /// <param name="dtos">模板消息DTO</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> CreateTemplateMessages(params TemplateMessageInputDto[] dtos);
        #endregion
        #region "更新模板消息"
        /// <summary>
        /// 更新模板消息
        /// </summary>
        /// <param name="dtos">模板消息DTO</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> UpdateTemplateMessages(params TemplateMessageInputDto[] dtos);
        #endregion
        #region "删除模板消息"
        /// <summary>
        /// 删除模板消息
        /// </summary>
        /// <param name="ids">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> DeleteTemplateMessages(params long[] ids);
        #endregion
        #region "发送模板消息"
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="messageIds">消息编号</param>
        /// <returns>业务操作结果</returns>
        Task<OperationResult> SendTemplateMessages(params long[] messageIds);
        #endregion

        #region "获取组织机构组键"
        /// <summary>
        /// 获取组织机构组键
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>组织机构组键</returns>
        string GetGroupKeyByOrganization(string key);
        #endregion
        #region "获取角色组键"
        /// <summary>
        /// 获取角色组键
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>角色组键</returns>
        string GetGroupKeyByRole(string key);
        #endregion
        #region "获取消息发送任务编号"
        /// <summary>
        /// 获取消息发送任务编号
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>消息发送任务编号</returns>
        string GetMessageSendJobId(string key);
        #endregion
        #region "获取消息删除任务编号"
        /// <summary>
        /// 获取消息删除任务编号
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>消息删除任务编号</returns>
        string GetMessageDeleteJobId(string key);
        #endregion
        #region "获取消息查询任务编号"
        /// <summary>
        /// 获取消息查询任务编号
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>消息查询任务编号</returns>
        string GetMessageQueryJobId(string key);
        #endregion
        #region "获取消息模板任务编号"
        /// <summary>
        /// 获取消息模板任务编号
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns>消息模板任务编号</returns>
        string GetMessageTemplateJobId(string key);
        #endregion

        #endregion

    }

}
